#include<bits/stdc++.h>
using namespace std;
inline void read(int &n)
{
    int x=0,f=1;
    char ch;
    for(ch=getchar();!(ch>='0'&&ch<='9')&&ch!='-';ch=getchar());
    if(ch=='-')
    {
        f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+ch-'0';
        ch=getchar();
    }
    n=x*f;
}
int T;
const int N=1e5+5;
int n,ans;
int a[2*N];
int co[2*N];
int dp[2][2*N];
void dfs(int dep)
{
    if(dep>n)
    {
        int js=0;
        for(int i=1;i<=n;i++)
        {
            int j=i-1;
            while(j)
            {
                if(co[i]==co[j])
                {
                    if(a[i]==a[j]) js+=a[i];
                    break;
                }
                j--;
            }
        }
        ans=max(ans,js);
        return ;
    }
    co[dep]=0;
    dfs(dep+1);
    co[dep]=1;
    dfs(dep+1);
}
void solution1()
{
    dfs(1);
    cout<<ans<<endl;
}
void solution2()
{
    cout<<"QwQ"<<endl;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    read(T);
    while(T--)
    {
        ans=0;
        read(n);
        for(int i=1;i<=n;i++)
        {
            read(a[i]);
        }
        if(n<=15) solution1();
        else solution2();
    }
    return 0;
}